package selenium;

import java.io.IOException;

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SeleniumProxyIp {
	public static void main(String[] args) {
		System.getProperties().setProperty("proxySet", "true");
		System.getProperties().setProperty("http.proxyHost", "114.115.140.25");//114.115.140.25:3128
		System.getProperties().setProperty("http.proxyPort", "3128");
		WebDriver webDriver = new ChromeDriver();
		// 设置代理
		/*String proxyIpAndPort = "114.115.140.25:3128";
		DesiredCapabilities cap = new DesiredCapabilities();
		Proxy proxy = new Proxy();
		proxy.setHttpProxy(proxyIpAndPort).setFtpProxy(proxyIpAndPort).setSslProxy(proxyIpAndPort);
		cap.setCapability(CapabilityType.ForSeleniumServer.AVOIDING_PROXY, true);
		cap.setCapability(CapabilityType.ForSeleniumServer.ONLY_PROXYING_SELENIUM_TRAFFIC, true);
		System.setProperty("http.nonProxyHosts", "localhost");
		cap.setCapability(CapabilityType.PROXY, proxy);*/
		// 访问网址

		try {
			webDriver.get("https://www.baidu.com/s?wd=ip");// 访问网址
			// 标题
		} catch (Exception e) {
			System.err.println("Exception: " + e);
		}
	}
}